﻿using Coldairarrow.Business.Base;
using Coldairarrow.Entity.Base;
using Coldairarrow.Entity.DTO;
using Coldairarrow.IBusiness.DTO;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.Base
{
    [Route("/Base/[controller]/[action]")]
    public class Base_RepairOrderController : BaseApiController
    {
        #region DI

        public Base_RepairOrderController(IBase_RepairOrderBusiness base_RepairOrderBus)
        {
            _base_RepairOrderBus = base_RepairOrderBus;
        }

        IBase_RepairOrderBusiness _base_RepairOrderBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<Base_RepairOrder>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _base_RepairOrderBus.GetDataListAsync(input);
        }

        [HttpPost]
        public async Task<Base_RepairOrder> GetTheData(IdInputDTO input)
        {
            return await _base_RepairOrderBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(Base_RepairOrder data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _base_RepairOrderBus.AddDataAsync(data);
            }
            else
            {
                await _base_RepairOrderBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _base_RepairOrderBus.DeleteDataAsync(ids);
        }
        /// <summary>
        /// 保存维修工单及明细数据
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task AddDataList(Base_Base_RepairOrderlistinfo data) {


            Base_RepairOrder aa =await _base_RepairOrderBus.GetTheDataAsyncQQQ(data.Id);
            if (aa==null)
            {
                await _base_RepairOrderBus.AddDataList(data);
            }
            else {
                await _base_RepairOrderBus.UpdateDataList(data);
            }
            
      
          
       
        }

        #endregion


        #region PDA设备维修操作
        /// <summary>
        /// 维修领药扫描二维码获取工件信息
        /// </summary>
        /// <param name="RepairOrderQrCode"></param>
        /// <returns></returns>
      [HttpPost]
        public async Task<Base_RepairOrderDetailsPDADTO> GetPDADataListInfo(string RepairOrderQrCode) {
            var ListData = await _base_RepairOrderBus.GetPDADataListInfo(RepairOrderQrCode);
            return ListData;
        }
        /// <summary>
        /// PDA扫码获取维修单数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<Base_RepairOrPDADTO> GetPDADataListMain(string RepairOrderQrCode) {
            var listData = await _base_RepairOrderBus.GetPDADataListMain(RepairOrderQrCode);
            return listData;
        
        }
        /// <summary>
        /// PDA维修领料  
        /// </summary>
        /// <param name="RepairOrderCode">RepairOrderCode 维修单编号</param>
        /// <param name="MaterialCode">物料编码</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Base_RepairOrderDetailsPDADTO> Base_RepairOrderDetailsPDANumberDTO( string RepairOrderCode, string MaterialCode) {
          
            var listData = await _base_RepairOrderBus.GetRepairOrderDetailsPDANumber(RepairOrderCode, MaterialCode);
            return listData;
        }
        /// <summary>
        /// PDA更新库存
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task UpdateStockUpDataAsync(UpdateInventory data) {
             await _base_RepairOrderBus.UpdateStockUpDataAsync(data);
        }
        /// <summary>
        /// 移除操作
        /// </summary>
        /// <param name="stockupQrCode">维修单二维码</param>
        /// <param name="packqrocde">物料二维码</param>
        /// <param name="nums">数量</param>
        /// <returns></returns>
        [HttpPost]
        public async Task DeleteStockUpDetailListDataAsync(string stockupQrCode, string packqrocde, double nums) {
            await _base_RepairOrderBus.DeleteStockUpDetailListDataAsync(stockupQrCode, packqrocde,nums);
        }
      /// <summary>
      /// 出库动作
      /// </summary>
      /// <param name="RefCode">维修单号</param>
      /// <param name="stockupQrCode">维修明细号</param>
      /// <returns></returns>
        [HttpPost]
        public  async Task SubmitStockUpDataAsync(string RefCode, string stockupQrCode) {
            await _base_RepairOrderBus.SubmitStockUpDataAsync(RefCode,stockupQrCode);
        }
        /// <summary>
        /// 扫描维修单号 获取出库数据
        /// </summary>
        /// <param name="RepairOrderQrCode"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Base_RepairOrderOK> GetPDADataListOK(string RepairOrderQrCode) {
            var data =await _base_RepairOrderBus.GetPDADataListOK(RepairOrderQrCode);
            return data;
        }

        /// <summary>
        /// 完成动作 反写 维修申请状态为已完成
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task Operationcompleted(string Id) {
            await _base_RepairOrderBus.Operationcompleted(Id);
        }
        #endregion
    }
}